package com.yunlankeji.stemcells.activity.mine;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yunlankeji.ganxibaozhijia.R;
import com.yunlankeji.stemcells.adapter.AddressAdapter;
import com.yunlankeji.stemcells.model.request.Address;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class mine_addressActivity extends AppCompatActivity {
    @BindView(R.id.tv_address_name)
    TextView tv_name;

    LinearLayout lt_adress_return,lt_address_edit,lt_address_item;
    TextView tv_increase_address,tv_phone,tv_location,tv_location_detail;
    RecyclerView rv_adress;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_address);
        lt_adress_return = findViewById(R.id.lt_address_return);
        tv_increase_address = findViewById(R.id.tv_increase_address);
        rv_adress = findViewById(R.id.rv_adress);
        lt_address_edit = findViewById(R.id.lt_address_edit);
        lt_address_item = findViewById(R.id.lt_address_item);
        tv_name = findViewById(R.id.tv_address_name);
        tv_phone = findViewById(R.id.tv_address_phone);
        tv_location_detail = findViewById(R.id.tv_location_detail);

        tv_increase_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mine_addressActivity.this,Address_newActivity.class);
                startActivity(intent);
            }
        });


        List<Address> addressList = new ArrayList<>();
        Address address1 = new Address("122223","12333333","03213123165465231");
        Address address2 = new Address("123","123","03213123231");

        addressList.add(address1);
        addressList.add(address2);
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        rv_adress.setLayoutManager(layoutManager);
        AddressAdapter addressAdapter= new AddressAdapter(addressList);


        rv_adress.setAdapter(addressAdapter);

        // 设置item及item中控件的点击事件
        addressAdapter.setOnItemClickListener(new AddressAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, AddressAdapter.ViewName viewName, int position) {
                //viewName可区分item及item内部控件
                switch (v.getId()){
                    case R.id.lt_address_edit:
//                    String name = tv_name.getText().toString();
//                    String phone = tv_phone.getText().toString();
//                    String location_detail = tv_location_detail.getText().toString();
                        Intent intent = new Intent();
                        intent.putExtra("name",addressList.get(position).getAddress_name());
                        intent.putExtra("phone",addressList.get(position).getAddress_phone());
                        intent.putExtra("location_detail",addressList.get(position).getAdress());
                        intent.setClass(mine_addressActivity.this,Address_editActivity.class);
//                    intent.putExtra("name", name);
//                    intent.putExtra("phone", phone);
//                    intent.putExtra("location_detail", location_detail);
                        startActivity(intent);
                        break;
                    case R.id.lt_address_item:
                        startActivity(new Intent(mine_addressActivity.this,Address_editActivity.class));
                        break;
                }
            }

            @Override
            public void onItemLongClick(View v) {

            }
        });


    }



}